<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>产品详情</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            margin: 0;
            padding: 20px;
        }
        .product-detail {
            max-width: 600px;
            margin: auto;
            background: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, .1);
        }
        .product-detail h1 {
            color: #333;
            font-size: 2em;
            margin-bottom: 20px;
        }
        .product-detail p {
            color: #555;
            line-height: 1.6;
        }
        .back-btn {
            display: inline-block;
            margin-top: 20px;
            padding: 10px 20px;
            background-color: #007bff;
            color: white;
            text-decoration: none;
            border-radius: 5px;
        }
        .back-btn:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body onload="fetchProductDetail()">
<div class="product-detail" id="productDetailContainer">
    <!-- 动态内容将插入此处 -->
</div>

<script>
    async function fetchProductDetail() {
        // 从URL参数中获取产品ID
        const urlParams = new URLSearchParams(window.location.search);
        const productId = urlParams.get('id');

        try {
            // 发送异步请求获取产品详情
            const response = await fetch(`/product/get?id=${productId}`);
            const productData = await response.json();

            if (productData.success && productData.object) {
                const product = productData.object;
                document.getElementById('productDetailContainer').innerHTML = `
                    <h1>${product.name}</h1>
                    <p><strong>价格：</strong>￥${product.price}</p>
                    <p><strong>简介：</strong>${product.introduce}</p>
                    <a href="product.html" class="back-btn">返回列表</a>
                `;
            } else {
                document.getElementById('productDetailContainer').innerText = '未找到相关产品';
            }
        } catch (error) {
            console.error('获取产品详情失败:', error);
            document.getElementById('productDetailContainer').innerText = '加载产品详情失败';
        }
    }
</script>
</body>
</html>